package com.eco.fanliapp.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.eco.fanliapp.common.response.ServerResponse;
import com.eco.fanliapp.dao.AppUserRedRewardMapper;
import com.eco.fanliapp.dao.AppUserRewardSetupMapper;
import com.eco.fanliapp.dao.SyTaskTypeMapper;
import com.eco.fanliapp.dao.SyUserTaskMapper;
import com.eco.fanliapp.entity.*;
import com.eco.fanliapp.service.*;
import com.eco.fanliapp.utils.DateFormatUtils;
import com.eco.fanliapp.utils.DateUtils;
import com.eco.fanliapp.vo.AppUserTaskVo;
import com.eco.fanliapp.vo.DaoTaoKeSuperCategoryInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.concurrent.TimeUnit;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author jobob
 * @since 2019-08-07
 */
@Service
public class SyTaskTypeServiceImpl extends ServiceImpl<SyTaskTypeMapper, SyTaskType> implements ISyTaskTypeService {

    @Autowired
    private SyTaskTypeMapper syTaskTypeMapper;
    @Autowired
    private SyUserTaskMapper syUserTaskMapper;
    @Autowired
    private IGoodsFreeService goodsFreeService;

    @Autowired
    private AppUserRedRewardMapper appUserRedRewardMapper;

    @Autowired
    private ISySwitchService iSySwitchService;

    @Autowired
    private ISySignSetupService iSySignSetupService;
    @Autowired
    private ISyUserMoneyService iSyUserMoneyService;
    @Autowired
    private IAppUserService iAppUserService;
    @Autowired
    private RedisTemplate redisTemplate;
    @Autowired
    private RedisTemplateService redisTemplateService;
    @Autowired
    private AppUserRewardSetupMapper appUserRewardSetupMapper;

    @Override
    public ServerResponse getAppTaskAll(Integer taskType, Long userId) {

        SySwitch sySwitchOnOff = null;
        if (redisTemplate.hasKey("userTaskPopOnOff")) {
            sySwitchOnOff = (SySwitch) redisTemplate.opsForValue().get("userTaskPopOnOff");
        } else {
            sySwitchOnOff = iSySwitchService.getById(4);//id4 阴影任务弹窗叉号开关
            redisTemplate.opsForValue().set("userTaskPopOnOff", sySwitchOnOff, 1, TimeUnit.HOURS);
        }

        Boolean onoff = true;//默认有关闭叉号

        if (sySwitchOnOff != null) {
            if (sySwitchOnOff.getState() == 1) {
                //有关闭开关
                onoff = true;
            } else {
                //没有关闭开关
                onoff = false;
            }

        }

        //是否弹窗
        Boolean popout = false; //关闭阴影任务弹窗
        HashMap map = new HashMap();
        Integer noviceNum = 0;
        Integer taskNum = 0;
        Integer loseNum = 0;
        Long loseTime = 0L;

        BigDecimal popoutMoney = new BigDecimal(0);

        //新人红包
        AppUserRedReward appUserRedReward = appUserRedRewardMapper.getNewRedPacket(userId, 1, null);
        //if(appUserRedReward != null && appUserRedReward.getHbStatus() == 4 && appUserRedReward.getInvalidTimeFlag() == 0)addInvalidTime(appUserRedReward);
        //任务红包
        AppUserRedReward appUserRedReward2 = appUserRedRewardMapper.getNewRedPacket(userId, 3, null);
        if (taskType == 1) {

            QueryWrapper queryWrapper = new QueryWrapper();
            queryWrapper.eq("user_id", userId);
            queryWrapper.eq("hb_type", 1);
            List<AppUserRedReward> appUserRedRewards = appUserRedRewardMapper.selectList(queryWrapper);
            if(appUserRedRewards == null || appUserRedRewards.size() == 0){
                return ServerResponse.createByErrorMessage(null);
            }

            List<AppUserTaskVo> list = syTaskTypeMapper.getAppTaskAll(taskType, userId);
            int noviceSum = list.size();
            for (AppUserTaskVo usertask : list
            ) {
                popoutMoney = popoutMoney.add(usertask.getTaskRewardMoney());
                usertask.setClick(true);
                usertask.setButtonName(usertask.getTaskButtonBeforeName());

                if (usertask != null && usertask.getTableId() == 1 && usertask.getTaskStatus() == null ) {
                    if (appUserRedReward != null && appUserRedReward.getHbStatus() == 5) {
                        usertask.setButtonName("已领取");
                        usertask.setClick(false);
                        popout = false;
                        noviceNum += 1;
                    } else if (appUserRedReward != null && appUserRedReward.getHbStatus() == 4){
                        usertask.setButtonName("已失效");
                        usertask.setClick(false);
                        popout = false;
                        loseNum += 1;
                    }

                }else if (usertask != null && usertask.getTableId() == 1 && usertask.getTaskStatus() == 1){
                    if (appUserRedReward != null && appUserRedReward.getHbStatus() == 5) {
                        usertask.setButtonName("已领取");
                        usertask.setClick(false);
                        popout = false;
                        noviceNum += 1;
                    } else if (appUserRedReward != null && appUserRedReward.getHbStatus() == 4){
                        usertask.setButtonName("已失效");
                        usertask.setClick(false);
                        popout = false;
                        loseNum += 1;
                    }
                }

                if (usertask != null && usertask.getTableId() == 2 && usertask.getTaskStatus() == null ) {
                    if (appUserRedReward2 != null && appUserRedReward2.getHbStatus() == 5) {
                        usertask.setButtonName("已领取");
                        usertask.setClick(false);
                        popout = false;
                        noviceNum += 1;
                    } else if (appUserRedReward2 != null && appUserRedReward2.getHbStatus() == 4){
                        usertask.setButtonName("已失效");
                        usertask.setClick(false);
                        popout = false;
                        loseNum += 1;
                    }

                }else if (usertask != null && usertask.getTableId() == 2 && usertask.getTaskStatus() == 1){
                    if (appUserRedReward != null && appUserRedReward.getHbStatus() == 5) {
                        usertask.setButtonName("已领取");
                        usertask.setClick(false);
                        popout = false;
                        noviceNum += 1;
                    } else if (appUserRedReward != null && appUserRedReward.getHbStatus() == 4){
                        usertask.setButtonName("已失效");
                        usertask.setClick(false);
                        popout = false;
                        loseNum += 1;
                    }
                }


                if (usertask != null && usertask.getTaskStatus() != null && usertask.getTaskStatus() == 5) {
                    usertask.setButtonName(usertask.getTaskButtonAfterName());
                    usertask.setClick(false);
                    popout = false;
                    noviceNum += 1;
                }


                if (usertask != null && usertask.getTaskStatus() != null && usertask.getTableId() == 2) {
                    if (usertask.getTaskStatus() == 3) {
                        usertask.setButtonName("已下单");
                        usertask.setTaskDesc("恭喜任务完成啦~收货成功8天后奖励即可到账");
                        usertask.setClick(false);
                        popout = false;
                    } else if (usertask.getTaskStatus() == 4) {
                        usertask.setButtonName("待入账");
                        usertask.setClick(false);
                        usertask.setTaskDesc("恭喜任务完成啦~收货成功8天后奖励即可到账");
                        popout = false;
                    } else if (usertask.getTaskStatus() == 6){
                        usertask.setButtonName("已失效");
                        usertask.setClick(false);
                        popout = false;
                        loseNum += 1;
                    }
                }
                if (usertask != null && usertask.getTaskStatus() != null && usertask.getTaskStatus() == 1) {
                    popout = false;
                }
            }
            if (noviceNum == 3 ) {
                return ServerResponse.createByErrorMessage(null);
            }
            if (noviceNum == 1 && loseNum ==2 ) {
                return ServerResponse.createByErrorMessage(null);
            }
            if (noviceNum == 2 && loseNum ==1 ) {
                return ServerResponse.createByErrorMessage(null);
            }
            Long time = 7 * 24 * 60 * 60 * 1000L + appUserRedReward.getInvalidTime();
            if(appUserRedReward != null && appUserRedReward.getHbStatus() == 4 && System.currentTimeMillis() > time){
                return ServerResponse.createByErrorMessage(null);
            }
            if(appUserRedReward2 != null && appUserRedReward2.getHbStatus() == 1){
                loseTime = appUserRedReward2.getInvalidTime();
            }

            if(loseTime > 0){
                loseTime = loseTime - System.currentTimeMillis();
            }

            map.put("list", list);
            map.put("loseTime", loseTime);
            map.put("noviceCaption", "新手任务");
            map.put("noviceSum", noviceSum);
            map.put("noviceNum", noviceNum);
            map.put("popout", popout);//暂时关闭阴影任务弹窗，ture弹，false不弹
            map.put("onoff", onoff);
            map.put("popoutMoney", popoutMoney);
            return ServerResponse.createBySuccess("新手任务", map);
        } else if (taskType == 2) {
            //7天签到金额
            SySignSetup sySignSetup = iSySignSetupService.getById(1);
            List<AppUserTaskVo> list = syTaskTypeMapper.getAppTaskAll(taskType, userId);
            List<AppUserTaskVo> listNew = new ArrayList<>();
            for (AppUserTaskVo appUserTaskVo : list) {
                appUserTaskVo.setClick(false);
                if (appUserTaskVo.getTableId() == 4) {//新人免费送
                    //1 根据userId查询用户
                    AppUser appUser = iAppUserService.selectAppUserByUserId(userId);
                    //新人免费送没有开始，加入列表。免单下单成功这个消失
                    ServerResponse<String> sr = goodsFreeService.checkHaveBuy(userId, 0);
                    if(appUser != null && appUser.getUserLoginTime() != null){
                        //以首次登陆时间为依据，判断时间是否超过7天
                        Date loginDate = appUser.getUserLoginTime();
                        Date loginDate2 = DateUtils.updateDayByDate(loginDate,7);
                        long time = loginDate2.getTime();
                        if(time >= System.currentTimeMillis()){
                            if (sr.getStatus() == 515) {
                                if (appUserTaskVo.getTaskStatus() == null || appUserTaskVo.getTaskStatus() == 1 || appUserTaskVo.getTaskStatus() == 2) {
                                    appUserTaskVo.setClick(true);
                                    appUserTaskVo.setButtonName("免费领");
                                    listNew.add(appUserTaskVo);
                                }
                            }
                        }

                    }

                } else if (appUserTaskVo.getTableId() == 5) {//送好友免费礼物+6元
                    appUserTaskVo.setClick(true);
                    appUserTaskVo.setButtonName("去邀请");
                    listNew.add(appUserTaskVo);
                } else if (appUserTaskVo.getTableId() == 6) {//每日购物+10金币
                    //完成这个任务后 按钮变成已完成，标题变成明日购物
                    if (appUserTaskVo.getTaskStatus() != null &&
                            (appUserTaskVo.getTaskStatus() == 3 || appUserTaskVo.getTaskStatus() == 4 || appUserTaskVo.getTaskStatus() == 5)
                    ) {
                        appUserTaskVo.setButtonName("已完成");
                        appUserTaskVo.setTaskName("明日购物");
                    } else {
                        appUserTaskVo.setClick(true);
                        appUserTaskVo.setButtonName("去购物");
                    }
                    listNew.add(appUserTaskVo);
                } else if (appUserTaskVo.getTableId() == 7) {//分享到微信群+10金币
                    //完成这个任务消失，第二天0点再展示
                    if (appUserTaskVo.getTaskStatus() == null || appUserTaskVo.getTaskStatus() == 1 || appUserTaskVo.getTaskStatus() == 2) {
                        appUserTaskVo.setButtonName("去分享");
                        appUserTaskVo.setClick(true);
                        listNew.add(appUserTaskVo);
                    }
                } else if (appUserTaskVo.getTableId() == 8) {//每日签到金币
                    //判断连续签到第几天
                    SyUserTask syUserTask_One = syUserTaskMapper.selectSignTaskDay(1, userId);
                    if(syUserTask_One == null){
                        appUserTaskVo.setTaskRewardNum(sySignSetup.getOneDayGoldNum());
                    }else if(syUserTask_One.getTaskSignDay() == 1){
                        appUserTaskVo.setTaskRewardNum(sySignSetup.getTwoDayGoldNum());
                    }else if(syUserTask_One.getTaskSignDay() == 2){
                        appUserTaskVo.setTaskRewardNum(sySignSetup.getThreeDayGoldNum());
                    }else if(syUserTask_One.getTaskSignDay() == 3){
                        appUserTaskVo.setTaskRewardNum(sySignSetup.getFourDayGoldNum());
                    }else if(syUserTask_One.getTaskSignDay() == 4){
                        appUserTaskVo.setTaskRewardNum(sySignSetup.getFiveDayGoldNum());
                    }else if(syUserTask_One.getTaskSignDay() == 5){
                        appUserTaskVo.setTaskRewardNum(sySignSetup.getSixDayGoldNum());
                    }else if(syUserTask_One.getTaskSignDay() == 6){
                        appUserTaskVo.setTaskRewardNum(50);
                    }else if(syUserTask_One.getTaskSignDay() == 7){
                        appUserTaskVo.setTaskRewardNum(sySignSetup.getOneDayGoldNum());
                    }
                    //完成这个任务后 按钮变成已完成
                    if (appUserTaskVo.getTaskStatus() != null &&
                            (appUserTaskVo.getTaskStatus() == 3 || appUserTaskVo.getTaskStatus() == 4 || appUserTaskVo.getTaskStatus() == 5)
                    ) {
                        appUserTaskVo.setButtonName("已完成");
                        appUserTaskVo.setClick(true);
                    } else {
                        appUserTaskVo.setClick(true);
                        appUserTaskVo.setButtonName("去签到");
                    }
                    listNew.add(appUserTaskVo);
                } else if (appUserTaskVo.getTableId() == 9) {//给好评拿金币

                    QueryWrapper<SyUserTask> queryWrapper = new QueryWrapper<>();
                    queryWrapper.eq("user_id", userId);
                    queryWrapper.eq("task_type_id", 9);
                    SyUserTask syUserTask = syUserTaskMapper.selectOne(queryWrapper);
                    if (syUserTask == null) {
                        //奖励后永久消失
                        if (appUserTaskVo.getTaskStatus() == null || appUserTaskVo.getTaskStatus() == 1 || appUserTaskVo.getTaskStatus() == 2) {
                            appUserTaskVo.setButtonName("去好评");
                            appUserTaskVo.setClick(true);
                            listNew.add(appUserTaskVo);
                        }
                    }

                } else if (appUserTaskVo.getTableId() == 10) {//查看推送
                    appUserTaskVo.setButtonName("去查看");
                    appUserTaskVo.setClick(true);
                    listNew.add(appUserTaskVo);

                } else if (appUserTaskVo.getTableId() == 11) {//好友完成复制商品链接+10金币
                    appUserTaskVo.setButtonName("去分享");
                    appUserTaskVo.setClick(true);
                    listNew.add(appUserTaskVo);
                }

                if (appUserTaskVo.getTaskStatus() != null && appUserTaskVo.getTableId() != 4 && appUserTaskVo.getTableId() != 9 && appUserTaskVo.getTaskStatus() == 5) {
                    taskNum += 1;
                }
            }


            map.put("list", listNew);
            map.put("taskCaption", "日常任务");
            map.put("taskSum", list.size()-2);
            map.put("taskNum", taskNum);
            return ServerResponse.createBySuccess("日常任务", map);
        }
        return null;

    }
    @Override
    public SyTaskType selectSyTaskTypeById(int id) {
        return syTaskTypeMapper.selectById(id);
    }

    /**
     * 签到界面
     * @param userId
     * @return
     */
    @Override
    public ServerResponse findAppTaskSignAll(Long userId) {
        HashMap map = new HashMap();
        //7天签到金额
        String redisKeyStr = "app_sign_setup_obj";
        SySignSetup sySignSetup = null;
        if (redisTemplateService.hasKey(redisKeyStr)) {
            sySignSetup = redisTemplateService.getTByKey(redisKeyStr, SySignSetup.class);
        }
        if (sySignSetup == null) {
            sySignSetup = iSySignSetupService.getById(1);
            redisTemplateService.set(redisKeyStr, sySignSetup, 60 * 5);
        }
        //根据用户id查询账户
        SyUserMoney syUserMoney = iSyUserMoneyService.selectByUserId(userId);


        if(syUserMoney == null){
            map.put("cashBalanceAmount","0");
            map.put("goldBalanceAmount","0");
        }else {
            map.put("cashBalanceAmount",syUserMoney.getCashBalanceAmount().toString());
            map.put("goldBalanceAmount",syUserMoney.getGoldBalanceAmount().toString());
        }


        //根据用户id 查询用户,判断推送是否开启1开，0关   11.10号暂时关闭，
       AppUser appUser = iAppUserService.selectAppUserByUserId(userId);
        if(appUser != null && appUser.getSignPush() == 1){
            map.put("signPush",1);
        }else {
            map.put("signPush",0);
        }
//        map.put("signPush",1);
        //判断连续签到第几天
        SyUserTask syUserTask = syUserTaskMapper.selectSignTaskDay(1,userId);
        if(syUserTask == null){
            map.put("signDay",1);
        }else if(syUserTask.getTaskSignDay() == 7 || syUserTask.getTaskSignDay() == 0){
            map.put("signDay",1);
        }else {
            map.put("signDay",syUserTask.getTaskSignDay()+1);
        }

        //任务列表
        List<AppUserTaskVo> list = syTaskTypeMapper.getAppTaskAll(3,userId);
        map.put("taskList",list);
        map.put("sySignSetup",sySignSetup);

        String url = "https://s.click.taobao.com/hWBctxv";
        map.put("jumpUrl",url);

        return ServerResponse.createBySuccess("签到日常任务", map);
    }

    @Override
    public void updateTaskRewardMoneyById(BigDecimal money, Integer tableId) {
        syTaskTypeMapper.updateTaskRewardMoneyById(money,tableId);
    }

    @Override
    public ServerResponse appUserTaskAll(Integer taskType, Long userId) {

        HashMap map = new HashMap();

        if (taskType == 1) {
           /* AppUser user = iAppUserService.selectAppUserByUserId(userId, 1);
            if(user != null && user.getUserLoginTime() != null){
                //以首次登陆时间为依据，判断时间是否超过7天
                Date loginDate = user.getUserLoginTime();
                Date loginDate2 = DateUtils.updateDayByDate(loginDate, 14);
                long time = loginDate2.getTime();
                if (time < System.currentTimeMillis()) {
                    return ServerResponse.createByErrorMessage(null);//显示时间已过期
                }
            }else {
                return ServerResponse.createByErrorMessage(null);//显示时间已过期
            }*/
            AppUserRewardSetup rewardSetup = null;
            if (redisTemplateService.hasKey("AppUserRewardSetup")) {
                rewardSetup = redisTemplateService.getTByKey("AppUserRewardSetup", AppUserRewardSetup.class);
            } else {
                rewardSetup = appUserRewardSetupMapper.selectByPrimaryKey(1);
                redisTemplateService.set("AppUserRewardSetup", rewardSetup, 60 * 60);
            }
            //是否弹窗
//            Boolean popout = false; //关闭阴影任务弹窗
            Integer noviceNum = 0;
            Integer loseNum = 0;
//            Long loseTime = 0L;
            BigDecimal popoutMoney = new BigDecimal(0);

            List<AppUserRedReward> appUserRedRewards = appUserRedRewardMapper.selectAppUserRedRewardList(userId);
            if(appUserRedRewards == null || appUserRedRewards.size() <= 0){
                return ServerResponse.createByErrorMessage("用户没有可用红包");
            }
            List<AppUserTaskVo> list = syTaskTypeMapper.getAppTaskAll(taskType, userId);
            int noviceSum = list.size();
            for (AppUserTaskVo usertask : list
            ) {
                popoutMoney = popoutMoney.add(usertask.getTaskRewardMoney());
                usertask.setClick(true);
                usertask.setButtonName(usertask.getTaskButtonBeforeName());
                //新人0.36元红包判断
                if (usertask != null && usertask.getTableId() == 1 && (usertask.getTaskStatus() == null || usertask.getTaskStatus() == 1)) {
                    if (appUserRedRewards.get(0) != null && appUserRedRewards.get(0).getHbStatus() == 5) {
                        usertask.setButtonName("已领取");
                        usertask.setClick(false);
                        noviceNum += 1;
                    } else if (appUserRedRewards.get(0) != null && appUserRedRewards.get(0).getHbStatus() == 4){
                        usertask.setButtonName("已失效");
                        usertask.setClick(false);
                        loseNum += 1;
                    }

                }
                //首购红包判断
                if (usertask != null && usertask.getTableId() == 2 && (usertask.getTaskStatus() == null || usertask.getTaskStatus() == 1) ) {
                    if (appUserRedRewards.get(1) != null && appUserRedRewards.get(1).getHbStatus() == 5) {
                        usertask.setButtonName("已领取");
                        usertask.setClick(false);
                        noviceNum += 1;
                    } else if (appUserRedRewards.get(1) != null && appUserRedRewards.get(1).getHbStatus() == 4){
                        usertask.setButtonName("已失效");
                        usertask.setClick(false);
                        loseNum += 1;
                    }

                }


                if (usertask != null && usertask.getTaskStatus() != null && usertask.getTaskStatus() == 5) {
                    usertask.setButtonName(usertask.getTaskButtonAfterName());
                    usertask.setClick(false);
                    noviceNum += 1;
                }


                if (usertask != null && usertask.getTaskStatus() != null && usertask.getTableId() == 2) {
                    if (usertask.getTaskStatus() == 3) {
                        usertask.setButtonName("已下单");
                        usertask.setTaskDesc("恭喜任务完成啦~收货成功"+rewardSetup.getTaskRedMoneyExpireTime()+"天后奖励即可到账");
                        usertask.setClick(false);
                    } else if (usertask.getTaskStatus() == 4) {
                        usertask.setButtonName("待入账");
                        usertask.setClick(false);
                        usertask.setTaskDesc("恭喜任务完成啦~收货成功"+rewardSetup.getTaskRedMoneyExpireTime()+"天后奖励即可到账");
                    } else if (usertask.getTaskStatus() == 6){
                        usertask.setButtonName("已失效");
                        usertask.setClick(false);
                        loseNum += 1;
                    }
                }
            }

            if (noviceNum == 3 || noviceNum+loseNum == 3) {
                return ServerResponse.createByErrorMessage(null);//任务已完成
            }

          /*  if(appUserRedRewards.get(0) != null){
                loseTime = appUserRedRewards.get(0).getInvalidTime();
                loseTime = loseTime - System.currentTimeMillis();
            }

            if(loseTime < 0){
                loseTime = 0L;
            }
*/
            map.put("list", list);
            map.put("loseTime", 0L);
            map.put("noviceCaption", "新手任务");
            map.put("noviceSum", noviceSum);//任务总数
            map.put("noviceNum", noviceNum);//任务完成数量
            map.put("popout", false);//暂时关闭阴影任务弹窗，ture弹，false不弹
            map.put("onoff", true);
            map.put("popoutMoney", popoutMoney);
            return ServerResponse.createBySuccess("新手任务", map);
        } else if (taskType == 2) {
            Integer taskNum = 0;
            //7天签到金额
            String redisKeyStr = "app_sign_setup_obj";
            SySignSetup sySignSetup = null;
            if (redisTemplateService.hasKey(redisKeyStr)) {
                sySignSetup = redisTemplateService.getTByKey(redisKeyStr, SySignSetup.class);
            }
            if (sySignSetup == null) {
                sySignSetup = iSySignSetupService.getById(1);
                redisTemplateService.set(redisKeyStr, sySignSetup, 60 * 5);
            }
            List<AppUserTaskVo> list = syTaskTypeMapper.getAppTaskAll(taskType, userId);
            List<AppUserTaskVo> listNew = new ArrayList<>();
            for (AppUserTaskVo appUserTaskVo : list) {
                appUserTaskVo.setClick(false);
                if (appUserTaskVo.getTableId() == 4) {//新人免费送
                    //1 根据userId查询用户
                    AppUser appUser = iAppUserService.selectAppUserByUserId(userId,1);
                    //新人免费送没有开始，加入列表。免单下单成功这个消失
                    ServerResponse<String> sr = goodsFreeService.checkHaveBuy(userId, 0);
                    if(appUser != null && appUser.getUserLoginTime() != null){
                        //以首次登陆时间为依据，判断时间是否超过7天
                        Date loginDate = appUser.getUserLoginTime();
                        Date loginDate2 = DateUtils.updateDayByDate(loginDate,7);
                        long time = loginDate2.getTime();
                        if(time >= System.currentTimeMillis()){
                            if (sr.getStatus() == 515) {
                                if (appUserTaskVo.getTaskStatus() == null || appUserTaskVo.getTaskStatus() == 1 || appUserTaskVo.getTaskStatus() == 2) {
                                    appUserTaskVo.setClick(true);
                                    appUserTaskVo.setButtonName("免费领");
                                    listNew.add(appUserTaskVo);
                                }
                            }
                        }

                    }

                } else if (appUserTaskVo.getTableId() == 5) {//送好友免费礼物+6元
                    appUserTaskVo.setClick(true);
                    appUserTaskVo.setButtonName("去邀请");
                    listNew.add(appUserTaskVo);
                } else if (appUserTaskVo.getTableId() == 6) {//每日购物+10金币
                    if (appUserTaskVo.getTaskStatus() != null &&
                            (appUserTaskVo.getTaskStatus() == 3 || appUserTaskVo.getTaskStatus() == 4 || appUserTaskVo.getTaskStatus() == 5)
                    ) {
                        appUserTaskVo.setButtonName("已完成");
                    } else {
                        appUserTaskVo.setClick(true);
                        appUserTaskVo.setButtonName("去购物");
                    }
                    listNew.add(appUserTaskVo);
                } else if (appUserTaskVo.getTableId() == 7) {//分享到微信群+10金币
                    //完成这个任务消失，第二天0点再展示
                    if (appUserTaskVo.getTaskStatus() == null || appUserTaskVo.getTaskStatus() == 1 || appUserTaskVo.getTaskStatus() == 2) {
                        appUserTaskVo.setButtonName("去分享");
                        appUserTaskVo.setClick(true);
                        listNew.add(appUserTaskVo);
                    }
                } else if (appUserTaskVo.getTableId() == 8) {//每日签到金币
                    //判断连续签到第几天
                    SyUserTask syUserTask_One = syUserTaskMapper.selectSignTaskDay(1, userId);
                    if(syUserTask_One == null){
                        appUserTaskVo.setTaskRewardNum(sySignSetup.getOneDayGoldNum());
                    }else if(syUserTask_One.getTaskSignDay() == 1){
                        appUserTaskVo.setTaskRewardNum(sySignSetup.getTwoDayGoldNum());
                    }else if(syUserTask_One.getTaskSignDay() == 2){
                        appUserTaskVo.setTaskRewardNum(sySignSetup.getThreeDayGoldNum());
                    }else if(syUserTask_One.getTaskSignDay() == 3){
                        appUserTaskVo.setTaskRewardNum(sySignSetup.getFourDayGoldNum());
                    }else if(syUserTask_One.getTaskSignDay() == 4){
                        appUserTaskVo.setTaskRewardNum(sySignSetup.getFiveDayGoldNum());
                    }else if(syUserTask_One.getTaskSignDay() == 5){
                        appUserTaskVo.setTaskRewardNum(sySignSetup.getSixDayGoldNum());
                    }else if(syUserTask_One.getTaskSignDay() == 6){
                        appUserTaskVo.setTaskRewardNum(50);
                    }else if(syUserTask_One.getTaskSignDay() == 7){
                        appUserTaskVo.setTaskRewardNum(sySignSetup.getOneDayGoldNum());
                    }
                    //完成这个任务后 按钮变成已完成
                    if (appUserTaskVo.getTaskStatus() != null &&
                            (appUserTaskVo.getTaskStatus() == 3 || appUserTaskVo.getTaskStatus() == 4 || appUserTaskVo.getTaskStatus() == 5)
                    ) {
                        appUserTaskVo.setButtonName("已完成");
                        appUserTaskVo.setClick(true);
                    } else {
                        appUserTaskVo.setClick(true);
                        appUserTaskVo.setButtonName("去签到");
                    }
                    listNew.add(appUserTaskVo);
                } else if (appUserTaskVo.getTableId() == 9) {//给好评拿金币

                    QueryWrapper<SyUserTask> queryWrapper = new QueryWrapper<>();
                    queryWrapper.eq("user_id", userId);
                    queryWrapper.eq("task_type_id", 9);
                    SyUserTask syUserTask = syUserTaskMapper.selectOne(queryWrapper);
                    if (syUserTask == null) {
                        //奖励后永久消失
                        if (appUserTaskVo.getTaskStatus() == null || appUserTaskVo.getTaskStatus() == 1 || appUserTaskVo.getTaskStatus() == 2) {
                            appUserTaskVo.setButtonName("去好评");
                            appUserTaskVo.setClick(true);
                            listNew.add(appUserTaskVo);
                        }
                    }

                } else if (appUserTaskVo.getTableId() == 10) {//查看推送
                    appUserTaskVo.setButtonName("去查看");
                    appUserTaskVo.setClick(true);
                    listNew.add(appUserTaskVo);

                } else if (appUserTaskVo.getTableId() == 11) {//好友完成复制商品链接+10金币
                    appUserTaskVo.setButtonName("去分享");
                    appUserTaskVo.setClick(true);
                    listNew.add(appUserTaskVo);
                }

                if (appUserTaskVo.getTaskStatus() != null && appUserTaskVo.getTableId() != 4 && appUserTaskVo.getTableId() != 9 && appUserTaskVo.getTaskStatus() == 5) {
                    taskNum += 1;
                }
            }

            map.put("list", listNew);
            map.put("taskCaption", "日常任务");
            map.put("taskSum", list.size()-2);
            map.put("taskNum", taskNum);
            return ServerResponse.createBySuccess("日常任务", map);
        }
        return ServerResponse.createByErrorMessage("请求失败");
    }
}
